<?php
/*this script belongs to show  the scheme details */
 $path = drupal_get_path('module', 'scheme');
 drupal_add_css($path . '/css/scheme.css');
 drupal_add_js($path . '/js/scheme.js');

function scheme(){
 global $base_url;
 global $language;
 if($language->language=='ta'){
	$lang= '/ta';
}else{
 $lang='';
}
    drupal_set_title(scheme);
 $output = '<div class="rsslogo">' . get_rss_feed("scheme_rssfeed") . '</div>    ';
 $output .= '<div id="viewmod_schemes_tab_'.$language->language.'">
        <div class="menu_tab view-header">
            <div class="department_wise">
                <a class="view_head_sel" href="'.$base_url.$lang.'/scheme/department_wise/">'.t('Department wise').'</a>       
            </div>
            <div class="beneficiary_wise">               
                <a class="inactive"  href="'.$base_url.$lang.'/scheme/beneficiary_wise">'.t('Beneficiary Wise').'</a>
            </div>       
            <div class="atoz_view">               
                <a class="inactive" href="'.$base_url.$lang.'/scheme/alpha_view">'.t('A to Z').'</a>
            </div>       
            <div class="search">               
                <a class="inactive"  href="'.$base_url.$lang.'/scheme/search">'.t('Search').'</a>
            </div>
        </div>       
        <div class="clear"></div>       
    </div>';
   
           
    my_db_change(1);
   
    $result = db_query("select DISTINCT dept_name,dep_id from depart_mst ORDER BY dept_name ASC");
    my_db_change(0);
         
      $output .= '<div class="result_inner">';
      if($language->language == 'ta'){     
          foreach($result as $item) {             
              $output .= '<div class="scheme_list"><p><a  href="'.$base_url.'/'.$language->language.'/scheme/department_wise/'.$item->dep_id.'">'.t(substr($item->dept_name,0,255)).'</a></p></div>';
          }
    }
    else {
         foreach($result as $item) {   
            $output .= '<div class="scheme_list"><p><a  href="'.$base_url.'/scheme/department_wise/'.$item->dep_id.'">'.t(substr($item->dept_name,0,255)).'</a></p></div>';
        }
      }
     
      $output .= '</div>';   
           
    $form['field'] = array(
        '#type' => 'fieldset',
        '#title' => '',
        '#description' => $output,
        '#tree' => TRUE,
    );
    return $form;
}
function dept_wise($deptId='') {
 global $base_url,$language;
  if($language->language=='ta'){
	$lang= '/ta';
}else{
 $lang='';
}
  $output = '<div class="rsslogo">' . get_rss_feed("scheme_rssfeed") . '</div>    ';
 $output .= '<div id="viewmod_schemes_tab_'.$language->language.'">
        <div class="menu_tab view-header">
            <div class="department_wise">
                <a class="view_head_sel" href="'.$base_url.$lang.'/scheme/department_wise/">'.t('Department wise').'</a>       
            </div>
            <div class="beneficiary_wise">               
                <a class="inactive"  href="'.$base_url.$lang.'/scheme/beneficiary_wise">'.t('Beneficiary Wise').'</a>
            </div>       
            <div class="atoz_view">               
                <a class="inactive"  href="'.$base_url.$lang.'/scheme/alpha_view">'.t('A to Z').'</a>
            </div>       
            <div class="search">               
                <a class="inactive"  href="'.$base_url.$lang.'/scheme/search">'.t('Search').'</a>
            </div>
        </div>       
        <div class="clear"></div>       
    </div>';
    if(!empty($deptId)){
        $cond = " AND b.field_scheme_concern_department_value = '" . (string)$deptId . "'";
    }
    $empty ='';
//    print_r($dep);
    my_db_change(1);
    //$lan_qry=db_query("select language from node a INNER JOIN content_type_scheme b ON a.nid =b.nid JOIN depart_mst AS c ON c.dep_id = CAST(b.field_scheme_concern_department_value AS INTEGER) and a.type='scheme'")->fetchField();
   
    $result = db_query("SELECT c.dept_name AS heading FROM
node AS a, field_data_field_scheme_concern_department AS b, depart_mst AS c
WHERE a.nid = b.entity_id AND a.vid = b.revision_id and (a.language='".$language->language."' or a.language = '') AND c.dep_id = CAST(b.field_scheme_concern_department_value AS INTEGER) AND a.status = 1" . $cond .
            " ORDER BY trim(a.title) ASC")->fetchField();   
   
    /*$count_qry = "SELECT count(a.title) FROM
                node AS a, content_type_scheme AS b, depart_mst AS c
                WHERE a.nid = b.nid AND a.vid = b.vid AND c.dep_id = CAST(b.field_scheme_concern_department_value AS INTEGER) AND a.status = 1" . $cond;   
    $count=db_query($count_qry);
    foreach($count as $item) {     
    //print_r($item->count);
    }
                   
    my_db_change(0);         
    $output .= '<div class="result_inner">';   
    if($language->language == 'ta'){     
    foreach($result as $item) {     
          $output .= '<div class="scheme_list"><p><a  href="'.$base_url.'/'.$language->language.'/scheme/data_view/'.$item->nid.'">'.t(substr($item->title,0,255)).'</a></p></div>';
          }
    }
    else {
        foreach($result as $item) {     
              $output .= '<div class="scheme_list"><p><a  href="'.$base_url.'/scheme/data_view/'.$item->nid.'">'.t(substr($item->title,0,255)).'</a></p></div>';
          }
    }    $output .= '</div>';
    */
   
    $query = db_select('node', 'a');
        $query->join('field_data_field_scheme_concern_department', 'b', 'a.nid =b.entity_id AND a.vid =b.revision_id AND b.field_scheme_concern_department_value = \'' .(string)$deptId .'\'');
        $query->join('depart_mst', 'c','CAST(b.field_scheme_concern_department_value as int)=  c.dep_id');
        $query->condition('a.language',$language->language);
        $query->condition('a.status','1');
        $query->condition('a.type','scheme');
        $query->fields('a',array('title','nid','vid'))->fields('b',array('field_scheme_concern_department_value','entity_id','revision_id'))
        ->fields('c',array('dep_id','dept_name'))->orderBy('a.title', 'ASC')->distinct('a.title','c.dep_id','a.nid','b.entity_id','b.field_scheme_description_value');
        $query_result=$query->extend('PagerDefault')->limit(15)->execute();
    //print_r( $query_result);
    my_db_change(0);
   
    $output .= '<div class="result_inner">';   
    $output .= '<div class="heading_name">'.t(substr($result,0,255)).'</div>';    
    $i=0;     
    foreach($query_result as $item) {
        //print_r($item);
        $deptname= $item->dept_name;
        $title=$item->title;       
        if($language->language == 'ta'){     
            $output .= '<div class="scheme_list"><p><a  href="'.$base_url.'/'.$language->language.'/scheme/data_view/'.$item->nid.'">'.t(substr($title,0,255)).'</a></p></div>';                         
        }
        else {
            $output .= '<div class="scheme_list"><p><a  href="'.$base_url.'/scheme/data_view/'.$item->nid.'">'.t(substr($title,0,255)).'</a></p></div>';          
           
        }
        $i++;
    }
    if($i == '0'){
             $output .='<div class="no_record">'.t('No Results Found').' </div>';
            }                   
    //$output .= '<div class="heading_name"><h3>'.substr($deptname,0,255).'</h3></div>';
    $output .= theme('pager');     
    $output .= '</div>';   
       
    $form['field'] = array(
        '#type' => 'fieldset',
        '#title' => '',
        '#description' => $output,
        '#tree' => TRUE,
    );
    return $form;
}
 
function data_view($nid='') {
   global $base_url;
   global $language;
   $url = $base_url . '/' . drupal_get_path('module', 'scheme');
     if(!empty($department_id)){
        $dept_cond = "AND c.field_scheme_concern_department_value = '" . (string)$department_id . "' ";
    }
   $output = '<div class="clear-block"><div style="float:right;clear:both;margin-right:20px;"><a href="javascript:history.go(-1)"><strong>Back</strong></a></div>';
   $output .= '<div class ="node_view_heading" style="clear:both;">';
   $output .= '<div class ="node_view_head_content">';
   $output .= '<img height="15" width="15" style="display: none;" class="node_view_top_corner" alt="" src= "'.$url.'/images/leftcurve.jpg" ?> ';         
   $output .= '<span class = "node_view_head_title"><br/>Scheme</span>';
   $output .= '</div></div><div class="clear"></div></div></div>';
  
    my_db_change(1);
    $qery = db_query("SELECT c.field_scheme_concern_department_value FROM field_data_field_scheme_concern_department AS c where c.entity_id = $nid");
    foreach($qery as $row){
        $depid=$row->field_scheme_concern_department_value;
    }
   
    $qry = db_query("SELECT a.title,b.dept_name,c.entity_id FROM node AS a, depart_mst as b,field_data_field_scheme_concern_department AS c WHERE a.nid = c.entity_id
AND a.vid = c.revision_id AND a.nid = $nid AND b.dep_id = cast(c.field_scheme_concern_department_value as int) AND a.status = 1 ORDER BY trim(a.title)");
    foreach($qry as $row){
        $title=$row->title;
        $nid=$row->entity_id;
        $dept_name=$row->dept_name;   
        $node = node_load($row->nid);
    }
    //print "<pre>";        print_r($node);        print "</pre>";
    $lan_qry=db_query("select language,tnid from node where nid=$nid");
    foreach($lan_qry as $row){
    //print_r($row);
        $content_language=$row->language;
        $tnid=$row->tnid;
    }
   
    if($content_language=='en' || $content_language=='ta') {
    $qury=db_query("select distinct n.nid,n.title ,d.dept_name                
        ,sp.sponsor_name,bv.beneficiaries_name,sb.benefits_name,dist.field_scheme_concern_district_value,f.filename,f.uri,so.unpublish_on ,spons.field_scheme_sponsored_by_value
,dval.field_scheme_concern_department_value,se.field_scheme_eligible_community_value,bf.field_scheme_beneficiaries_value,ind.field_scheme_introduced_on_value,sval.field_scheme_associate_value ,eval.field_scheme_eligibility_value,dt.field_scheme_description_value,inval.field_scheme_eligible_income_value,p.field_scheme_funding_pattern_value,
agf.field_scheme_eligible_age_from_value,agt.field_scheme_eligible_age_to_value ,avl.field_scheme_how_to_avail_value,org.field_scheme_org_value,
typ.field_scheme_type_value from node as n LEFT join field_data_field_scheme_concern_department as dval on dval.entity_id=n.nid
LEFT join depart_mst as d on d.dep_id =cast(dval.field_scheme_concern_department_value as integer) LEFT join field_data_field_scheme_sponsored_by as spons on spons.entity_id=n.nid
LEFT join scheme_sponsors AS sp on sp.id = CAST(spons.field_scheme_sponsored_by_value AS INTEGER) LEFT join field_data_field_scheme_beneficiaries as bf on bf.entity_id=n.nid
LEFT join scheme_beneficiaries AS bv on bv.id = CAST(bf.field_scheme_beneficiaries_value AS INT)  LEFT join field_data_field_scheme_benfits_type as tval on tval.entity_id=n.nid
LEFT join scheme_benefits AS sb on sb.id = CAST(tval.field_scheme_benfits_type_value AS INT)  LEFT join field_data_field_scheme_concern_district as dist on dist.entity_id=n.nid and dist.revision_id=n.vid LEFT join scheduler as so on so.nid=n.nid   LEFT join field_data_field_scheme_upload as up on up.entity_id=n.nid
LEFT JOIN file_managed as f on up.field_scheme_upload_fid=f.fid  LEFT join field_data_field_scheme_funding_pattern as p ON p.entity_id = n.nid
LEFT JOIN field_data_field_scheme_eligible_community AS se ON se.entity_id = n.nid  LEFT join field_data_field_scheme_introduced_on as ind on ind.entity_id= n.nid
LEFT join field_data_field_scheme_associate as sval on sval.entity_id = n.nid LEFT join field_data_field_scheme_eligibility as eval on eval.entity_id = n.nid and eval.revision_id=n.nid LEFT join field_data_field_scheme_description as dt on dt.entity_id=n.nid LEFT JOIN field_data_field_scheme_eligible_income as inval on inval.entity_id=n.nid
LEFT join field_data_field_scheme_eligible_age_from as agf on agf.entity_id=n.nid  LEFT join field_data_field_scheme_eligible_age_to as agt on agt.entity_id=n.nid
LEFT join field_data_field_scheme_how_to_avail as avl on avl.entity_id = n.nid  LEFT join field_data_field_scheme_org as org on org.entity_id = n.nid
LEFT join field_data_field_scheme_type as typ on typ.entity_id=n.nid  where n.nid=$nid and n.type='scheme' and  n.status = 1  and n.tnid = $tnid
 ");
    }
    else {
     $qury=db_query("select distinct n.nid,n.title ,d.dept_name ,sp.sponsor_name,bv.beneficiaries_name,sb.benefits_name,dist.field_scheme_concern_district_value,f.filename,f.uri,so.unpublish_on ,spons.field_scheme_sponsored_by_value ,dval.field_scheme_concern_department_value,se.field_scheme_eligible_community_value,bf.field_scheme_beneficiaries_value,ind.field_scheme_introduced_on_value,sval.field_scheme_associate_value ,eval.field_scheme_eligibility_value,dt.field_scheme_description_value,inval.field_scheme_eligible_income_value,p.field_scheme_funding_pattern_value,
agf.field_scheme_eligible_age_from_value,agt.field_scheme_eligible_age_to_value ,avl.field_scheme_how_to_avail_value,org.field_scheme_org_value,
typ.field_scheme_type_value from node as n LEFT join field_data_field_scheme_concern_department as dval on dval.entity_id=n.nid
LEFT join depart_mst as d on d.dep_id =cast(dval.field_scheme_concern_department_value as integer) LEFT join field_data_field_scheme_sponsored_by as spons on spons.entity_id=n.nid
 LEFT join scheme_sponsors AS sp on sp.id = CAST(spons.field_scheme_sponsored_by_value AS INTEGER) LEFT join field_data_field_scheme_beneficiaries as bf on bf.entity_id=n.nid
 LEFT join scheme_beneficiaries AS bv on bv.id = CAST(bf.field_scheme_beneficiaries_value AS INT)  LEFT join field_data_field_scheme_benfits_type as tval on tval.entity_id=n.nid
 LEFT join scheme_benefits AS sb on sb.id = CAST(tval.field_scheme_benfits_type_value AS INT)  LEFT join field_data_field_scheme_concern_district as dist on dist.entity_id=n.nid and dist.revision_id=n.vid LEFT join scheduler as so on so.nid=n.nid   LEFT join field_data_field_scheme_upload as up on up.entity_id=n.nid
 LEFT JOIN file_managed as f on up.field_scheme_upload_fid=f.fid  LEFT join field_data_field_scheme_funding_pattern as p ON p.entity_id = n.nid
 LEFT JOIN field_data_field_scheme_eligible_community AS se ON se.entity_id = n.nid  LEFT join field_data_field_scheme_introduced_on as ind on ind.entity_id= n.nid
 LEFT join field_data_field_scheme_associate as sval on sval.entity_id = n.nid LEFT join field_data_field_scheme_eligibility as eval on eval.entity_id = n.nid and eval.revision_id=n.nid LEFT join field_data_field_scheme_description as dt on dt.entity_id=n.nid LEFT JOIN field_data_field_scheme_eligible_income as inval on inval.entity_id=n.nid
  LEFT join field_data_field_scheme_eligible_age_from as agf on agf.entity_id=n.nid  LEFT join field_data_field_scheme_eligible_age_to as agt on agt.entity_id=n.nid
  LEFT join field_data_field_scheme_how_to_avail as avl on avl.entity_id = n.nid  LEFT join field_data_field_scheme_org as org on org.entity_id = n.nid
  LEFT join field_data_field_scheme_type as typ on typ.entity_id=n.nid  where n.nid= $nid and  n.status = 1  and n.type='scheme' ");
}
    foreach($qury as $row){    //print "<pre>";print_r($row);print "</pre>";
        $btitle=$row->title;
        $dept_namee=$row->dept_name;
        $sponsor_name=$row->sponsor_name;
        $beneficiaries_name=$row->beneficiaries_name;
        $benefits_name=$row->benefits_name;
        $paternval=$row->field_scheme_funding_pattern_value;
        $dval=$row->field_scheme_description_value;
        $incomeval=$row->field_scheme_eligible_income_value;
        $ageval=$row->field_scheme_eligible_age_from_value;
        $agetoval=$row->field_scheme_eligible_age_to_value;
        $paternval=$row->field_scheme_funding_pattern_value;
        $dval=$row->field_scheme_description_value;
        $incomeval=$row->field_scheme_eligible_income_value;
        $agefromval=$row->field_scheme_eligible_age_from_value;
        $agetoval=$row->field_scheme_eligible_age_to_value;
        $community_value=$row->field_scheme_eligible_community_value;
        $availval=$row->field_scheme_how_to_avail_value;
        $orgval=$row->field_scheme_org_value;       
        $schemtypeval=$row->field_scheme_type_value;
        $distt= $row->field_scheme_concern_district_value;        
        $filename=$row->filename;
        $filepath=$row->uri;
        $unpublish_on=$row->unpublish_on;
        $eligible=$row->field_scheme_eligibility_value;   
        $associateval=$row->field_scheme_associate_value;
        $intro=$row->field_scheme_introduced_on_value;
    }
    //print "<pre>";   
   
     if($distt!=0) {
          $sqry = db_query("select n.title,d.dt_name from node AS n JOIN district_mst AS d ON nid = $orgval and d.dt_cd in ($distt)");
     }
     else {
         if($orgval !='') {
           $sqry = db_query("select n.title from node AS n where nid = $orgval");
            $dist_name = "All Districts";
        }
        else {
            //$output .= "<div>No Results found</div>";
            $dist_name = "All Districts";
        }
     }
   
    foreach($sqry as $row){  //print "<pre>"; print_r($row); print "</pre>";
     $orgname = $row->title;
    if($distt!=0){
      $dist_name .= $row->dt_name.",";
      }
     }
   if($distt!=0){
   $dist_name = substr($dist_name,0,-1);
   }
   if($community_value != ''){
     $com = db_query("select community_name from community_mst where com_id=$community_value");
    }
    foreach($com as $row){
         $comm = $row->community_name;
    }
    my_db_change(0);
         
   
    $output .= '<div class="node_viewlist_even">';     
    $output .= '<span class = "left_column">'.t('Concerned Department').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.t($dept_namee).'</span>';
    $output .= '<div class="clr"></div></div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column">'.t('Concerned District').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.t($dist_name).'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class="node_viewlist_even">';     
    $output .= '<span class = "left_column">'.t('Organisation Name').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    if ($orgname!=''){
        $output .= '<span class = "right_column">'.t($orgname).'</span>';
    }else{
        $output .='<span class = "right_column">--</span>';
    }
    $output .= '<div class="clr"></div></div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column">'.t('Scheme Details').'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Title / Name').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.t($btitle).'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Associated Scheme').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.$associateval.'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Sponsored By').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.t($sponsor_name).'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Funding Pattern').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.$paternval.'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class="node_viewlist_even">';     
    $output .= '<span class = "left_column">'.t('Beneficiaries').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.t($beneficiaries_name).'</span>';
    $output .= '<div class="clr"></div></div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column">'.t('Benefits Types').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .= '<span class = "right_column">'.t($benefits_name).'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column">'.t('Eligibility criteria').'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Income').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    if ($income!=''){
        $output .='<span class = "right_column">'.$income.'</span>';
    }else{
        $output .='<span class = "right_column">--</span>';
    }
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Age').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .='<span class = "right_column">'.$agefromval.'--'.$agetoval.'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Community').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    if ($community_value!=''){
        $output .='<span class = "right_column">'.t($comm).'</span>';
    }
    else{
        $output .='<span class = "right_column">--</span>';
    }
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Other Details').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    if ($eligible!=''){
        $output .='<span class = "right_column">'.t($eligible).'</span>';
    }
    else{
        $output .='<span class = "right_column">--</span>';
    }
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_odd">';
    $output .= '<span class = "left_column">'.t('How To Avail').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    if ($availval!=''){
        $output .= '<span class = "right_column">'.t($availval).'</span>';
    }
    else{
        $output .='<span class = "right_column">--</span>';
    }
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column">'.t('Validity of the Scheme').'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Introduced On').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .='<span class = "right_column">';
	$intro = strtotime($intro);
    $output .= format_date($intro, 'custom', 'M d, Y');
    $output .= '</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Valid Upto').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .='<span class = "right_column">';
    if($unpublish_on != ''){
        $output .= format_date($unpublish_on, 'custom', 'M d, Y');
    }
    else{
        $output .='<span class = "right_column">--</span>';
    }
    $output .= '</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    $output .= '<div class = "node_viewlist_even">';
    $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Description').'</span>';
    $output .= '<span class = "middle_column"> : </span>';
    $output .='<span class = "right_column">'.t($dval).'</span>';
    $output .= '<div class="clr"></div>';
    $output .= '</div>';
   
    if($schemtypeval == 'download' || $schemtypeval == 'online')
    {   
        $output .= '<div class = "node_viewlist_odd">';
        $output .= '<span class = "left_column">'.t('Scheme Type').'</span>';
        $output .= '<span class = "middle_column"> : </span>';
        $output .= '<span class = "right_column">'.t($schemtypeval).'</span>';
        $output .= '<div class="clr"></div>';
        $output .= '</div>';
    }
   
    /*
    $url = file_create_url($filepath);
    $url = parse_url($url);
    print_r($url);
    print $filepat = $url['path'];*/
   
    $wrapper = file_stream_wrapper_get_instance_by_uri($filepath);
    if($wrapper == true){
         $path = $wrapper->getDirectoryPath() . "/" . file_uri_target($filepath);
    }
    $filepat="'http://cms.tn.gov.in/$path'";
   
    if($schemtypeval == 'download')
    {
        $output .= '<div class = "node_viewlist_odd">';
        $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Uploaded File').'</span></span>';
        $output .= '<span class = "middle_column"> : </span>';
        $output .= '<span class = "right_column">';
        $output .= '<a href="javascript:void(0);" onClick="return tnportal_window(' . $filepat . ');">'.t($filename).'</a>';
        $output .= '</span>';
        $output .= '<div class="clr"></div>';
        $output .= '</div>';
    }
    if($schemtypeval == 'online')
    {
        $output .= '<div class = "node_viewlist_odd">';
        $output .= '<span class = "left_column"><span class="whitespace"></span>'.t('Reference URL').'</span></span>';
        $output .= '<span class = "middle_column"> : </span>';
        $output .= '<span class = "right_column"><a href="javascript:void(0);" onClick="return tnportal_ext_window('.$filepat.');">'.t($filepath).'</a></span>';
        $output .= '<div class="clr"></div>';
        $output .= '</div>';
    }
    $output .= '<div class ="node_view_bottom">';
    $output .= '<div class ="node_view_bottom_content">';
    $output .= '<img height="15" width="15" style="display: none;" class="node_view_bottom_corner" alt="" src= "'.$url.'/images/bottomleft.jpg" ?>';
    $output .= '</div></div>';
   
    $form['field'] = array(
            '#type' => 'fieldset',
            '#title' => '',
            '#description' => $output,
            '#tree' => TRUE,
        );
    return $form;
 }
function get_rss_feed($links) {
    global $base_url;
   
    $http = 'http://';
    if(isset($_SERVER['HTTPS']))
    $http = 'https://';
   
   
    $cmsbaseurl = $http.$_SERVER['HTTP_HOST']."/tnportal_latest/";
   
    $rssicon = '<a href="'.$cmsbaseurl.$links.'" target="_blank"><img src="'.$base_url.'/sites/all/modules/scheme/images/rss_feed_icon.gif" alt="RSS Icon" /></a>';
    return $rssicon;
}

?>